/*
 ------------------------------------------------------------------------------
 Copyright (C) 2006-2007 Team Blur.

 This file is part of the Quantum Engine source code.

 The Quantum Engine source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The Quantum Engine source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the Quantum Engine source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


#include "sg_local.h"

void	Light_Spawn (entity_t *self);

typedef struct {
	const char *	className;
	void			(*spawn)(entity_t *);
} spawn_t;

static spawn_t		sg_spawn[] = {
	{"light",					Light_Spawn},
	{NULL,						NULL}
};


bool SG_SpawnEntity (entity_t *entity, script_t *script){
	spawn_t	*spawn;
	// Parse the entity dictionary
	if (!entity->spawnDict.Parse(script))
		return false;

	// Parse the class name
	if (!entity->spawnDict.GetString("className", &entity->className, "")){
		odSystem->Printf(S_COLOR_RED "SG_SpawnEntity: entity %i with no class name\n", entity->state.number);
		return false;
	}
	// Call the spawn function
	for (spawn = sg_spawn; spawn->className; spawn++){
		if (!Str_ICompare(spawn->className, entity->className)){
			spawn->spawn(entity);
			return true;
		}
	}

	odSystem->Printf(S_COLOR_RED "SG_SpawnEntity: '%s' doesn't have a spawn function\n", entity->className);

	return false;
}
